package com.admin.business.background.venusSysActivity;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 活动表
 * @create: 2023-10-28 17:24:13
 **/
@Service("venusSysActivityService")
@Slf4j
public class VenusSysActivityService{

    @Resource
    VenusSysActivityDao venusSysActivityDao;

    /**
     * 添加活动表,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:发布者ID
     *                   - sponsor_name:发起人
     *                   - activity_name:活动名称
     *                   - activity_number:报名人数
     *                   - activity_expert:管理员认证 0、正常；1、失效 ；2、已认证； 
     *                   - activity_browse:浏览量
     *                   - activity_cost:报名费用
     *                   - activity_amount:总金额
     *                   - activity_address:活动详细地址
     *                   - activity_tel:活动联系人电话
     *                   - activity_contact_person:活动联系人
     *                   - activity_description:活动说明
     *                   - activity_province:省级
     *                   - activity_city:市级
     *                   - activity_live_pictures:活动现场图片
     *                   - activity_area:区级
     *                   - activity_type:活动类型(1.线下活动 2.筹集经费)
     *                   - activity_states:活动状态( 0 报名中 1 结束 2 下架)
     *                   - activity_img:图片路径
     *                   - activity_date:开始时间
     *                   - activity_date_end:结束时间
     *                   - activity_send_type:活动快开始是否发过短信 0.未发 1.已发
     *                   - activity_time:报名截止时间
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:是否删除：0、正常，1、已删除；
     *                   - activity_isreflect:体现状态 0.审核中 1.已提现
     * @return
     * @author Ht
     * @create: 2023-10-28 17:24:13
     */
    @OpenApi
    public Return addVenusSysActivity(CDO cdoRequest) {
        venusSysActivityDao.addVenusSysActivity(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新活动表数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:发布者ID
     *                   - sponsor_name:发起人
     *                   - activity_name:活动名称
     *                   - activity_number:报名人数
     *                   - activity_expert:管理员认证 0、正常；1、失效 ；2、已认证； 
     *                   - activity_browse:浏览量
     *                   - activity_cost:报名费用
     *                   - activity_amount:总金额
     *                   - activity_address:活动详细地址
     *                   - activity_tel:活动联系人电话
     *                   - activity_contact_person:活动联系人
     *                   - activity_description:活动说明
     *                   - activity_province:省级
     *                   - activity_city:市级
     *                   - activity_live_pictures:活动现场图片
     *                   - activity_area:区级
     *                   - activity_type:活动类型(1.线下活动 2.筹集经费)
     *                   - activity_states:活动状态( 0 报名中 1 结束 2 下架)
     *                   - activity_img:图片路径
     *                   - activity_date:开始时间
     *                   - activity_date_end:结束时间
     *                   - activity_send_type:活动快开始是否发过短信 0.未发 1.已发
     *                   - activity_time:报名截止时间
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:是否删除：0、正常，1、已删除；
     *                   - activity_isreflect:体现状态 0.审核中 1.已提现
     * @return
     * @author Ht
     * @create: 2023-10-28 17:24:13
     */
    @OpenApi
    public Return updateVenusSysActivityById(CDO cdoRequest) {
        venusSysActivityDao.updateVenusSysActivityById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除活动表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-10-28 17:24:13
     */
    @OpenApi
    public Return deleteVenusSysActivityById(CDO cdoRequest){
        int count = venusSysActivityDao.deleteVenusSysActivityById(cdoRequest.getString("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除活动表数据
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-10-28 17:24:13
     */
    @OpenApi
    public Return deleteVenusSysActivity(CDO cdoRequest) {
        int count = venusSysActivityDao.deleteVenusSysActivity(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取活动表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-10-28 17:24:13
     */
    @OpenApi
    public Return getVenusSysActivityById(CDO cdoRequest) {
        CDO cdoMapperResult = venusSysActivityDao.getVenusSysActivityById(cdoRequest.getString("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取活动表数据列表
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-10-28 17:24:13
     */
    @OpenApi
    public Return getVenusSysActivityListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysActivityDao.getVenusSysActivityListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysActivityDao.getVenusSysActivityCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取活动表数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-10-28 17:24:13
     */
    @OpenApi
    public Return getVenusSysActivityListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysActivityDao.getVenusSysActivityListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysActivityDao.getVenusSysActivityCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
